package com.bng8.mcms.configuration;

import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.datasource.DataSourceDecipher;
import com.mybatisflex.core.keygen.KeyGenerators;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisFlexConfiguration implements MyBatisFlexCustomizer {

    /*@Bean
    public DataSourceDecipher dataSourceDecipher() {
        return (property,value) -> switch (property) {
            case URL, USERNAME, PASSWORD ->  new String(Base64.getDecoder().decode(value));
        };
    }*/

    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {

        /* ID 生成策略 */
        FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
        keyConfig.setKeyType(KeyType.Generator);
        /* flexId：独创的 FlexID 算法生成数据库主键 */
        keyConfig.setValue(KeyGenerators.flexId);

        /*启动时，不显示mybatis-flex LOGO*/
        flexGlobalConfig.setPrintBanner(false);
        /* ID 生成策略 */
        flexGlobalConfig.setKeyConfig(keyConfig);
        /*默认的逻辑删除字段*/
        flexGlobalConfig.setLogicDeleteColumn("del_flag");
        /*默认的乐观锁字段*/
        flexGlobalConfig.setVersionColumn("version");

        FlexGlobalConfig.getDefaultConfig().setTenantColumn("tenant_id");
        flexGlobalConfig.setPrintBanner(false);
    }
}